﻿Imports System.Data
Imports System.Data.SqlClient

Public Class MonHocDAO
    Private Shared lenhInsert As SqlCommand
    Private Shared lenhUpdate As SqlCommand
    Private Shared lenhDelete As SqlCommand
    Private dataProvider As DataProvider

    Public Sub New()
        dataProvider = New DataProvider
    End Sub
    Public Shared Function GetData() As DataTable
        Dim dt As DataTable = dataProvider.Executequery("sp_XuatMonHoc")
        Return dt
    End Function

    Public Shared Sub ThemMH(ByVal mh As MonHocDTO)
        Dim sql As String

        sql = "INSERT INTO MONHOC(MaMonHoc,TenMonHoc,NgayBatDau,NgayKetThuc,SoTinChi) VALUES(@MaMonHoc,@TenMonHoc,@NgayBatDau,@NgayKetThuc,@SoTinChi)"
        lenhInsert = New SqlCommand()
        lenhInsert.CommandText = sql
        Dim thamSo As SqlParameter

        thamSo = New SqlParameter("@MaMonHoc", SqlDbType.VarChar)
        thamSo.SourceColumn = mh.MaMonHoc
        lenhInsert.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@TenMonHoc", SqlDbType.NVarChar)
        thamSo.SourceColumn = mh.TenMonHoc
        lenhInsert.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@NgayBatDau", SqlDbType.DateTime)
        thamSo.SourceColumn = mh.NgayBatDau
        lenhInsert.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@NgayKetThuc", SqlDbType.DateTime)
        thamSo.SourceColumn = mh.NgayKetThuc
        lenhInsert.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@SoTinChi", SqlDbType.Int)
        thamSo.SourceColumn = mh.SoTinChi
        lenhInsert.Parameters.Add(thamSo)

    End Sub
    Public Shared Sub UpDateMH(ByVal mh As MonHocDTO)
        Dim sql As String

        sql = "UPDATE MONHOC SET TenMonHoc=@TenMonHoc,NgayBatDau=@NgayBatDau,NgayKetThuc=@NgayKetThuc,SoTinChi=@SoTinChi WHERE MaMonHoc=@MaMonHoc"
        lenhUpdate = New SqlCommand()
        lenhUpdate.CommandText = sql
        Dim thamSo As SqlParameter

        thamSo = New SqlParameter("@MaMonHoc", SqlDbType.VarChar)
        thamSo.SourceColumn = mh.MaMonHoc
        lenhUpdate.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@TenMonHoc", SqlDbType.NVarChar)
        thamSo.SourceColumn = mh.TenMonHoc
        lenhUpdate.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@NgayBatDau", SqlDbType.DateTime)
        thamSo.SourceColumn = mh.NgayBatDau
        lenhUpdate.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@NgayKetThuc", SqlDbType.DateTime)
        thamSo.SourceColumn = mh.NgayKetThuc
        lenhUpdate.Parameters.Add(thamSo)

        thamSo = New SqlParameter("@SoTinChi", SqlDbType.Int)
        thamSo.SourceColumn = mh.SoTinChi
        lenhUpdate.Parameters.Add(thamSo)
    End Sub
    Public Shared Sub DeleteMH(ByVal qlmhDTO As MonHocDTO)
        Dim sql As String
        sql = "DELETE FROM  MONHOC WHERE MaMonHoc=@MaMonHoc"
        lenhDelete = New SqlCommand()
        lenhDelete.CommandText = sql
        Dim thamSo As SqlParameter
        thamSo = New SqlParameter("@MaMonHoc", SqlDbType.VarChar)
        thamSo.SourceColumn = "MaMonHoc"
        lenhDelete.Parameters.Add(thamSo)
    End Sub
    Public Shared Sub CapNhat(ByVal bangMonHoc As DataTable)
        'dataProvider.GhiBang(bangMonHoc, "MONHOC", lenhInsert, lenhUpdate, lenhDelete)
        dataProvider.GhiBang(bangMonHoc, "MONHOC")
    End Sub
    Public Shared Function LayDSMonHoc() As DataTable
        Return dataProvider.DocBang("SELECT MaMonHoc,TenMonHoc,NgayBatDau,NgayKetThuc,SoTinChi FROM MONHOC")
    End Function
    Public Shared Function LayCauTrucBang() As DataTable
        Return dataProvider.DocCauTruc("SELECT * FROM MONHOC")
    End Function
End Class
